<p>Before Java 8, the only way to partially support closures in Java was by using anonymous inner classes. But the syntax of anonymous classes may
seem unwieldy and unclear.</p>
<p>With Java 8, most uses of anonymous inner classes should be replaced by lambdas to highly increase the readability of the source code.</p>
<p><strong>Note</strong> that this rule is automatically disabled when the project’s <code>sonar.java.source</code> is lower than <code>8</code>.</p>
<h2>Noncompliant Code Example</h2>
<pre>
myCollection.stream().map(new Mapper&lt;String,String&gt;() {
  public String map(String input) {
    return new StringBuilder(input).reverse().toString();
  }
});

Predicate&lt;String&gt; isEmpty = new Predicate&lt;String&gt; {
    boolean test(String myString) {
        return myString.isEmpty();
    }
}
</pre>
<h2>Compliant Solution</h2>
<pre>
myCollection.stream().map(input -&gt; new StringBuilder(input).reverse().toString());

Predicate&lt;String&gt; isEmpty = myString -&gt; myString.isEmpty();
</pre>

